package com.farm.observer;

// 观察者模式使用示例
public class ObserverPatternDemo {
    public static void main(String[] args) {
        EnvironmentSensor sensor = new EnvironmentSensor();

        AgriculturalMachineObserver seeder = new AgriculturalMachineObserver("播种机#1");
        AgriculturalMachineObserver sprayer = new AgriculturalMachineObserver("喷药机#1");

        sensor.registerObserver(seeder);
        sensor.registerObserver(sprayer);

        // 模拟环境数据变化
        sensor.setMeasurements(25.5f, 60.0f, 45.0f);
        System.out.println("-------------------");
        sensor.setMeasurements(28.0f, 65.0f, 75.0f);
    }
}